// pages/gaiaddresto/gaiaddresto.js
Page({

    /**
     * 页面的初始数据
     */
   
    data: {
        list:{
            // name:"李四",
            // phone:"18000897345",
            // addres:"广东省广州市000区"
        },
        name:"",
        phone:"",
        addres:"",
        index:null
    },
    name(options){
        let getname=options.detail.value;
        // console.log("name",getname);
        this.setData({
            name:getname
        })
    },
    phone(options){
        let getphone=options.detail.value;
        // console.log("phone",getphone)
        this.setData({
            phone:getphone
        })
    },
    addres(options){
        
        let getaddres=options.detail.value;
        // console.log("addres",getaddres)
        this.setData({
            addres:getaddres
        })
    },
    gai(){
        // console.log("123");

        let addlists= wx.getStorageSync("addersslists");
           
        if(addlists){
            var telreg=/^(13[0-9]|15[0-9]|17[0-9]|18[0-9]|14[0-9]|19[0-9])[0-9]{8}$/;
            if(telreg.test(this.data.phone)){
                let data={
                    name:this.data.name,
                    phone:this.data.phone,
                    address:this.data.addres
                }
                let lsitpps = addlists[this.data.index];
                lsitpps=data;
                addlists[this.data.index] =lsitpps;
                wx.setStorageSync('addersslists',addlists);

                wx.navigateTo({
                    url:"/pages/address/address"
                })
            }else{
                wx.showToast({
                    title: '请填写正确信息',
                    icon: 'none',
                    duration: 2000//持续的时间
                  })
                console.log("请填写正确信息")
                console.log("请填写正确信息")
            }

            
        }
       
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
           console.log(options)
           let indexto = options.index;
           console.log(indexto);
           this.setData({
              index: indexto
           })
        let addlists= wx.getStorageSync("addersslists")
           if(addlists){
                let lsitpps = addlists[indexto]
                console.log(lsitpps)
                // let data
                this.setData({
                    // list:lsitpps
                    name:lsitpps.name,
                    phone:lsitpps.phone,
                    addres:lsitpps.address
                })
        }
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        // this.setData({
        //     name:this.data.list.name,
        //     phone:this.data.list.phone,
        //     addres:this.data.list.addres
        // })
        // console.log(this.data.list.name)
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})